package cn.iocoder.yudao.module.data.controller.admin.dscategory.dto;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import lombok.Data;

/**
 * 数据源信息
 */
@Data
public class DBInfoDto {
    private String name;
    private String description;
    private String dbType;
    private String host;
    private String port;
    private String username;
    private String password;
    private String dbName;

    public DBInfoDto(String name,
                     String description,
                     String dbType,
                     String host,
                     String port,
                     String username,
                     String password,
                     String dbName) {
        this.name = name;
        this.description = description;
        this.dbType = dbType;
        this.host = host;
        this.port = port;
        this.username = username;
        this.password = password;
        this.dbName = dbName;
    }

    public DBInfoDto(String configuration) {
        JSONObject jsonObject = JSONUtil.parseObj(configuration);
        this.name = jsonObject.getStr("name");
        this.description = jsonObject.getStr("description");
        this.dbType = jsonObject.getStr("type");
        this.host = jsonObject.getStr("host");
        this.port = jsonObject.getStr("port");
        this.username = jsonObject.getStr("username");
        this.password = jsonObject.getStr("password");
        this.dbName = jsonObject.getStr("dbName");
    }

    public DBInfoDto() {

    }

    // Getters and Setters
}
